// pages/bill/bill.js

const requestToGetBill = require('../../utils/request.js').requestToGetBill
const toBillPayPage = require('../../utils/wx-navigate.js').toBillPayPage
const toRecordDeatilPage = require('../../utils/wx-navigate.js').toRecordDeatilPage

//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabArray: [{ prop: '', label: '待交账单' }, { prop: '', label: '交租记录' }],
    billList:[],
    payList:[],
    currentIndex:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.toGetData()
    app.updateBillPageData = this.toGetData
  },

  toGetData(){
    requestToGetBill("", "NOTPAY", res => {
      this.setData({
        billList: res.list
      })
    })

    requestToGetBill("", "SUCCESS&&CLOSED", res => {
      this.setData({
        payList: res.list
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.toGetData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  
  bindbillitemtap(e){
    let bill = e.currentTarget.dataset.bill
    if (bill.trade_state === "SUCCESS" || bill.trade_state === "CLOSED"){
      toRecordDeatilPage(e.currentTarget.dataset.bill)
    }else{
      toBillPayPage(e.currentTarget.dataset.bill)
    }
  },

  payTabClick(e) {
    this.setData({
      currentIndex: e.detail.currentIndex
    })

  }
})